package com.junmeng.afloatingball;

import static com.junmeng.libfloating.tab.TabLog.FLOATING_ACTION_LOG;
import static com.junmeng.libfloating.tab.TabLog.FLOATING_KEY_LOG;
import static com.junmeng.libfloating.tab.TabLog.FLOATING_KEY_LOG_LEVEL;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.junmeng.afloatingball.databinding.ActivityBottomNavigationBinding;
import com.junmeng.libfloating.widget.LogRecyclerView;

public class BottomNavigationActivity extends AppCompatActivity {

    private ActivityBottomNavigationBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityBottomNavigationBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_bottom_navigation);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.navView, navController);
    }

    public void onClickEnterActivity(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    public void onClickPostLog(View view) {
        Intent intent = new Intent();
        intent.setAction( FLOATING_ACTION_LOG);
        intent.putExtra(FLOATING_KEY_LOG, "a test append log " + Math.random());
        sendBroadcast(intent);
    }

    public void onClickPostInfoLog(View view) {
        Intent intent = new Intent();
        intent.setAction( FLOATING_ACTION_LOG);
        intent.putExtra(FLOATING_KEY_LOG, "a test append log " + Math.random());
        intent.putExtra(FLOATING_KEY_LOG_LEVEL, LogRecyclerView.LogType.INFO);
        sendBroadcast(intent);
    }

    public void onClickPostErrorLog(View view) {
        Intent intent = new Intent();
        intent.setAction( FLOATING_ACTION_LOG);
        intent.putExtra(FLOATING_KEY_LOG, "a test append log " + Math.random());
        intent.putExtra(FLOATING_KEY_LOG_LEVEL, LogRecyclerView.LogType.ERROR);
        sendBroadcast(intent);
    }
}